#!/bin/sh
cd ../../
#cp -r tfextern tensorflow/tensorflow
#cp platforms/osx/libtensorflow.sh tensorflow/tensorflow/tools/ci_build/builds/

cd tensorflow
tensorflow/tools/ci_build/osx/libtensorflow_cpu.sh
cd ..
mkdir -p lib/osx
cp -f tensorflow/bazel-bin/tensorflow/tfextern/libtfextern.so lib/osx/libtfextern.dylib
#cp -fL tensorflow/bazel-bin/tensorflow/libtensorflow_framework.dylib lib/osx/
chmod u+w lib/osx/libtfextern.dylib
install_name_tool -change @rpath/libtfextern.so @rpath/libtfextern.dylib lib/osx/libtfextern.dylib
#install_name_tool -change @rpath/libtensorflow_framework.1.dylib @rpath/libtensorflow_framework.dylib lib/osx/libtfextern.dylib
install_name_tool -id @rpath/libtfextern.dylib lib/osx/libtfextern.dylib
chmod u-w lib/osx/libtfextern.dylib

if [ -f tensorflow/bazel-bin/tensorflow/libtensorflow_framework.dylib ]
then
  cp -fL tensorflow/bazel-bin/tensorflow/libtensorflow_framework.dylib lib/osx/libtensorflow_framework.dylib
  chmod u+w lib/osx/libtensorflow_framework.dylib
  #install_name_tool -change @rpath/libtensorflow_framework.1.dylib @rpath/libtensorflow_framework.dylib lib/osx/libtensorflow_framework.dylib
  install_name_tool -id @rpath/libtensorflow_framework.dylib lib/osx/libtensorflow_framework.dylib
  chmod u-w lib/osx/libtensorflow_framework.dylib
  chmod u+w lib/osx/libtfextern.dylib
  install_name_tool -change @rpath/libtensorflow_framework.1.dylib @rpath/libtensorflow_framework.dylib lib/osx/libtfextern.dylib
  chmod u-w lib/osx/libtfextern.dylib
fi
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="x86_64"
